using System;
using System.ComponentModel;
using System.Diagnostics;
using XmlStudio.DataLayer;
using System.Windows;

namespace XmlStudio.ViewModel.Node {
    [DebuggerDisplay("Text: {Text}")]
    public class XmlTextViewModel : XmlNodeViewModel, INotifyPropertyChanged {
        #region Fields
        string text;
        #endregion

        #region Properties
        public string Text {
            get { return this.text; }
            set {
                this.text = value;
                OnPropertyChanged("Text");
            }
        }
        #endregion

        public override string ToString() {
            return string.Format("Text: {0}", Text);
        }

        #region Constructors
        public XmlTextViewModel(BigXmlNode node, IInputElement commandTarget)
            : base(Guid.NewGuid().ToString(), node, commandTarget) {
            this.Refresh();
        }
        #endregion

        #region Events
        public event PropertyChangedEventHandler PropertyChanged;
        #endregion

        #region Event handlers
        protected void OnPropertyChanged(string propertyName) {
            if(this.PropertyChanged != null) {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion

        public override void Refresh() {
            this.Text = this.Node.Value;
        }
    }
}
